package com.android.tnovoselec.schedule.fragment;

import com.actionbarsherlock.app.SherlockFragment;
import com.android.tnovoselec.schedule.R;
import com.android.tnovoselec.schedule.dto.ItemDto;
import com.android.tnovoselec.schedule.dto.ItemsResultHolder;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

public class ItemDetailsFragment extends SherlockFragment {

	private ItemDto item;

	EditText title;
	EditText notes;
	TextView hoursFrom;
	TextView hoursTo;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		Bundle args = getArguments();
		if (args != null){
			int itemID = args.getInt("itemID");
			item = ItemsResultHolder.getItemById(itemID);
		}
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.item_details, container, false);
		title = (EditText) v.findViewById(R.id.item_details_title);
		notes = (EditText) v.findViewById(R.id.item_details_notes);
		hoursFrom = (TextView) v.findViewById(R.id.item_details_hours_from);
		hoursTo = (TextView) v.findViewById(R.id.item_details_hours_to);
		
		if (item != null){
			title.setText(item.getTitle());
			notes.setText(item.getNotes());
			hoursFrom.setText(item.getHoursFrom());
			hoursTo.setText(item.getHoursTo());
		}
		
		return v;
	}

}
